package org.xshaokuang.loginandemail;

import cn.nukkit.Player;
import cn.nukkit.event.EventHandler;
import cn.nukkit.event.EventPriority;
import cn.nukkit.event.Listener;
import cn.nukkit.event.player.PlayerJoinEvent;
import cn.nukkit.event.player.PlayerQuitEvent;
import org.xshaokuang.loginandemail.email.EmailDataManager;
import org.xshaokuang.loginandemail.login.LoginDataManager;
import org.xshaokuang.loginandemail.login.LoginForm;

public class MyListener implements Listener {

    EmailDataManager emailDataManager = MainPlugin.getInstance().getEmailDataManager();

    LoginDataManager loginDataManager = MainPlugin.getInstance().getLoginDataManager();

    public MyListener() {
    }

    @EventHandler(priority = EventPriority.HIGHEST)
    public void onPlayerJoin(PlayerJoinEvent event) {

        Player player = event.getPlayer();
        loginDataManager.loadFromConfig(player.getName());
        LoginForm loginForm = new LoginForm(loginDataManager);
        loginForm.sendForm(player);
    }

    @EventHandler
    public void onPlayerQuit(PlayerQuitEvent event) {
        Player player = event.getPlayer();
        emailDataManager.saveToConfig(player.getName());
    }
}
